-
Notifications
You must be signed in to change notification settings - Fork 864
.NET: [BREAKING] Refactor ChatMessageStore methods to be similar to AIContextProvider and add filtering support #2604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
.NET: [BREAKING] Refactor ChatMessageStore methods to be similar to AIContextProvider and add filtering support #2604
Conversation
…sages in right order. Fix unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces a breaking refactoring of the ChatMessageStore interface to align with the AIContextProvider pattern, providing more explicit control over when and how messages are persisted. The changes replace the generic GetMessagesAsync and AddMessagesAsync methods with lifecycle-aware InvokingAsync and InvokedAsync methods that receive rich context about agent invocations.
Key changes:
- Replaced
GetMessagesAsync()withInvokingAsync(InvokingContext)to provide context about the current invocation when retrieving messages - Replaced
AddMessagesAsync(messages)withInvokedAsync(InvokedContext)to provide detailed context including request messages, AI context provider messages, response messages, and any exceptions - Added
ChatMessageStoreMessageFilterdecorator to enable filtering of messages before they are stored or retrieved - Added extension methods
WithMessageFilters()andWithAIContextProviderMessageRemoval()to simplify common filtering scenarios
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStore.cs |
Core interface refactoring with new InvokingAsync and InvokedAsync methods, plus new context classes InvokingContext and InvokedContext |
dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStoreExtensions.cs |
New extension methods for adding message filters and AI context provider message removal |
dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStoreMessageFilter.cs |
New decorator class that wraps a ChatMessageStore to enable filtering messages |
dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryChatMessageStore.cs |
Updated implementation to use new interface methods |
dotnet/src/Microsoft.Agents.AI.CosmosNoSql/CosmosChatMessageStore.cs |
Updated implementation to use new interface methods with Cosmos DB storage |
dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowMessageStore.cs |
Updated implementation to use new interface methods for workflow scenarios |
dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowHostAgent.cs |
Updated to use internal AddMessages method directly instead of the refactored interface methods |
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs |
Updated to call InvokingAsync and InvokedAsync with proper context, tracking message store messages separately |
dotnet/samples/GettingStarted/Agents/Agent_Step07_3rdPartyThreadStorage/Program.cs |
Updated sample to implement new interface methods |
dotnet/samples/GettingStarted/AgentWithRAG/AgentWithRAG_Step01_BasicTextRAG/Program.cs |
Added example of using WithAIContextProviderMessageRemoval() to filter search result messages |
dotnet/samples/GettingStarted/AgentProviders/Agent_With_CustomImplementation/Program.cs |
Updated custom agent implementation to use new interface methods |
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatMessageStoreTests.cs |
Updated base tests to use new interface methods |
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/InMemoryChatMessageStoreTests.cs |
Updated tests to verify new interface behavior |
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/ChatMessageStoreMessageFilterTests.cs |
New test file with comprehensive coverage for the filter decorator |
dotnet/tests/Microsoft.Agents.AI.CosmosNoSql.UnitTests/CosmosChatMessageStoreTests.cs |
Updated tests to use new interface methods with Cosmos DB |
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs |
Updated unit tests to verify new interface integration |
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_BackgroundResponsesTests.cs |
Updated tests for background response scenarios |
| Integration test fixtures | Updated all integration test fixtures to use InvokingAsync for retrieving messages |
dotnet/src/Microsoft.Agents.AI.Abstractions/InMemoryChatMessageStore.cs
Outdated
Show resolved
Hide resolved
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Abstractions/ChatMessageStoreExtensions.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
Motivation and Context
#2518
#2054
Description